package cn.fl.audit.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.audit.condition.AudCreditPassOpinionQueryCondition;
import cn.fl.audit.constant.AudStandingBookConstant;
import cn.fl.audit.service.IAudCreditPassOpinionService;
import cn.fl.audit.vo.AudCreditExtInfoVO;
import cn.fl.audit.vo.AudCreditPassOpinionVO;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.vo.CstBscInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.project.condition.PrjCstBscInfoQueryCondition;
import cn.fl.project.constant.PrjCstBscInfoConstant;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjCstBscInfoService;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjCstBscInfoVO;
import cn.fl.system.constant.SysLogConstant;

/**
 * @Description: 信审通过意见 控制层
 */
@Controller
@RequestMapping("/audit/audCreditPassOpinion")
public class AudCreditPassOpinionController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(AudCreditPassOpinionController.class);

	/**
	 * AudCreditPassOpinion 服务层BEAN
	 */
	@Autowired
	private IAudCreditPassOpinionService audCreditPassOpinionService;
	
	/**
	 * 项目基础信息服务
	 */
	@Autowired
	private IPrjBscInfoService prjBscInfoService;
	
	/**
	 * 项目客户信息服务
	 */
	@Autowired
	private IPrjCstBscInfoService prjCstBscInfoService;
	
	/**
	 * 客户信息服务
	 */
	@Autowired
	private ICstBscInfoService cstBscInfoService;

	/**
	 * 到信审通过意见预览页面
	 */
	@RequestMapping(value = "/toPreviewPage.do", method = { RequestMethod.GET})
	public ModelAndView toPreviewPage(HttpServletRequest request, HttpServletResponse response) {
		BaseLogUtils.info(logger, "toPreviewPage", "到信审通过意见预览页面.", CurrentThreadContext.getCurrentUserName());
		ModelAndView view = new ModelAndView("audit/audCreditPassOpinion/audCreditPassOpinionPreviewPage");
		String id = request.getParameter("id");
		String previewString = "";
		if(StringUtils.isNotEmpty(id)){
			previewString = this.audCreditPassOpinionService.getPreviewString(Long.valueOf(id));
		}
		view.addObject("previewString", previewString);
		return view;
	}
	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("audit/audCreditPassOpinion/list");
		BaseLogUtils.info(logger, "toListPage", "跳转到列表页面.", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 到修改页面-信审通过意见
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String projectId = request.getParameter("projectId");//项目ID
		String proIntId = request.getParameter("proIntId");//流程实例ID
		String prdTypCd = request.getParameter("prdTypCd");//产品类型
		ModelAndView view = new ModelAndView("audit/audCreditPassOpinion/audCreditPassOpinionAdd");
		view.addObject("id", id);
		view.addObject("projectId", projectId);
		view.addObject("proIntId", proIntId);
		
		/**查询刷新页面字段依据*/ 
		if(StringUtils.isNotEmpty(projectId)){
			/**1.项目ID-->客户ID-->客户表信息-->客户类型*/
			PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(projectId));
			if(null!=prjBscInfoVO){
				Long cstId = prjBscInfoVO.getCstId();
				CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectDetailById(cstId);
				if(null!=cstBscInfoVO){
					//承租人类型
					view.addObject("tenantTypCd", cstBscInfoVO.getCstTypCd());
				}
			}
			/**2.项目ID+客户关系(担保人)-->项目客户担保人-->担保人类型*/
			PrjCstBscInfoQueryCondition guarantorQC = new PrjCstBscInfoQueryCondition();
			guarantorQC.setPrjId(Long.valueOf(projectId));
			guarantorQC.setCstRlTyp(PrjCstBscInfoConstant.CST_Rl_ATTR_GUARANTOR);
			List<PrjCstBscInfoVO> guarantorList = this.prjCstBscInfoService.searchList(guarantorQC);
			if(CollectionUtils.isNotEmpty(guarantorList)){
				PrjCstBscInfoVO guarantorVO = guarantorList.get(0);
				//担保人类型
				view.addObject("guarantorTypCd", guarantorVO.getCstTypCd());
			}
		}
		//产品类型
		view.addObject("prdTypCd", prdTypCd);
		
		/**下拉数据*/
		//执行政策标准
		List<KeyValueVO> policyStandatrdsCdList = this.audCreditPassOpinionService.searchPolicyStandatrdsCdList();
		view.addObject("policyStandatrdsCdList", policyStandatrdsCdList);
		//是否符合标准
		List<KeyValueVO> standardCdList = this.audCreditPassOpinionService.searchStandardCdList();
		view.addObject("standardCdList", standardCdList);
		//执行模板
		List<KeyValueVO> executeTemplateCdList = this.audCreditPassOpinionService.searchExecuteTemplateCdList();
		view.addObject("executeTemplateCdList", executeTemplateCdList);
		//购车行为
		List<KeyValueVO> buyCdList = this.audCreditPassOpinionService.searchBuyCdList();
		view.addObject("buyCdList", buyCdList);
		//资产实力
		List<KeyValueVO> lesseeAssetsCdList = this.audCreditPassOpinionService.searchLesseeAssetsCdList();
		view.addObject("lesseeAssetsCdList", lesseeAssetsCdList);
		//车辆配置
		List<KeyValueVO> carConfigCdList = this.audCreditPassOpinionService.searchCarConfigCdList();
		view.addObject("carConfigCdList", carConfigCdList);
		//融资方案
		List<KeyValueVO> financePlanCdList = this.audCreditPassOpinionService.searchFinancePlanCdList();
		view.addObject("financePlanCdList", financePlanCdList);
		//运营情况
		List<KeyValueVO> operationSituationCdList = this.audCreditPassOpinionService.searchOperationSituationCdList();
		view.addObject("operationSituationCdList", operationSituationCdList);
		//运营经验
		List<KeyValueVO> operationExperienceCdList = this.audCreditPassOpinionService.searchOperationExperienceCdList();
		view.addObject("operationExperienceCdList", operationExperienceCdList);
		//第二还款来源
		List<KeyValueVO> paymentSourceCdList = this.audCreditPassOpinionService.searchPaymentSourceCdList();
		view.addObject("paymentSourceCdList", paymentSourceCdList);
		//履行职责
		List<KeyValueVO> fulfilCdList = this.audCreditPassOpinionService.searchFulfilCdList();
		view.addObject("fulfilCdList", fulfilCdList);
		//电话态度
		List<KeyValueVO> attitudeCdList = this.audCreditPassOpinionService.searchAttitudeCdList();
		view.addObject("attitudeCdList", attitudeCdList);
		//可操作性评价
		List<KeyValueVO> maneuverabilityCdList = this.audCreditPassOpinionService.searchManeuverabilityCdList();
		view.addObject("maneuverabilityCdList", maneuverabilityCdList);
		//资产证明
		List<KeyValueVO> assetsProveCdList = this.audCreditPassOpinionService.searchAssetsProveCdList();
		view.addObject("assetsProveCdList", assetsProveCdList);
		//与承租人关系
		List<KeyValueVO> relationshipCdList = this.audCreditPassOpinionService.searchRelationshipCdList();
		view.addObject("relationshipCdList", relationshipCdList);
		
		BaseLogUtils.info(logger, "toModifyPage", "跳转到修改页面.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 到动态字段组件页面-信审通过意见-承租人信息
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toTenantDynamicFldPage.do", method = { RequestMethod.GET,RequestMethod.POST })
	public ModelAndView toTenantDynamicFldPage(HttpServletRequest request, HttpServletResponse response) {
		String bizTypCd = request.getParameter("bizTypCd");
		String bizCd = request.getParameter("bizCd");
		ModelAndView view = new ModelAndView("audit/audCreditPassOpinion/audPassOpinionTenantDycPage");
		if(StringUtils.isNotEmpty(bizTypCd) && StringUtils.isNotEmpty(bizCd)){
			view.addObject("bizTypCd", bizTypCd);
			view.addObject("bizCd", bizCd);
		}else{
			view.addObject("bizTypCd", "");
			view.addObject("bizCd", "");
		}
		return view;
	}
	
	/**
	 * 到动态字段组件页面-信审通过意见-担保人信息
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toGuarantorDynamicFldPage.do", method = { RequestMethod.GET,RequestMethod.POST })
	public ModelAndView toGuarantorDynamicFldPage(HttpServletRequest request, HttpServletResponse response) {
		String bizTypCd = request.getParameter("bizTypCd");
		String bizCd = request.getParameter("bizCd");
		ModelAndView view = new ModelAndView("audit/audCreditPassOpinion/audPassOpinionGuarantorDycPage");
		if(StringUtils.isNotEmpty(bizTypCd) && StringUtils.isNotEmpty(bizCd)){
			view.addObject("bizTypCd", bizTypCd);
			view.addObject("bizCd", bizCd);
		}else{
			view.addObject("bizTypCd", "");
			view.addObject("bizCd", "");
		}
		return view;
	}
	
	/**
	 * 到动态字段组件页面-信审通过意见-乘用车增加
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toCarDynamicFldPage.do", method = { RequestMethod.GET,RequestMethod.POST })
	public ModelAndView toCarDynamicFldPage(HttpServletRequest request, HttpServletResponse response) {
		String bizTypCd = request.getParameter("bizTypCd");
		String bizCd = request.getParameter("bizCd");
		ModelAndView view = new ModelAndView("audit/audCreditPassOpinion/audPassOpinionCarDycPage");
		if(StringUtils.isNotEmpty(bizTypCd) && StringUtils.isNotEmpty(bizCd)){
			view.addObject("bizTypCd", bizTypCd);
			view.addObject("bizCd", bizCd);
		}else{
			view.addObject("bizTypCd", "");
			view.addObject("bizCd", "");
		}
		return view;
	}
	
	/**
	 * 根据 项目ID|流程实例ID 获取信审通过意见信息
	 * @param request
	 * @param response
	 * @return
	 * @throws BaseException
	 */
	@RequestMapping(value = "/getByProjectIdAndProIntId.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getByProjectIdAndProIntId(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String projectId = request.getParameter("projectId");
		String proIntId = request.getParameter("proIntId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(projectId)||StringUtils.isEmpty(proIntId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_AUD_PROINT_ID_NOT_EMPTY + SysLogConstant.LOG_AUD_PROJECT_ID_NOT_EMPTY);
			BaseLogUtils.error(logger, "getByProjectIdAndProIntId", "获取数据,缺少必要参数条件.projectId:"+projectId+",proIntId:"+proIntId, CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			AudCreditPassOpinionQueryCondition qc = new AudCreditPassOpinionQueryCondition();
			qc.setProIntId(proIntId);
			qc.setProjectId(Long.valueOf(projectId));
			AudCreditPassOpinionVO vo = this.audCreditPassOpinionService.selectAudCreditPassOpinionByQc(qc);
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getByProjectIdAndProIntId", "获取数据,数据不存在.projectId:"+projectId+",proIntId:"+proIntId, CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getByProjectIdAndProIntId", "获取数据.projectId:"+projectId+",proIntId:"+proIntId, CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getByProjectIdAndProIntId", "获取失败.[projectId:"+projectId+",proIntId:"+proIntId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getByProjectIdAndProIntId", "获取失败.[projectId:"+projectId+",proIntId:"+proIntId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String searchName = request.getParameter("demo.name");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		AudCreditPassOpinionQueryCondition qc = new AudCreditPassOpinionQueryCondition();
		if (StringUtils.isNotEmpty(searchName)) {
		}
		page.setCondition(qc);

		Pager pager = new Pager();//this.audCreditPassOpinionService.searchListPage(page);
		List<AudCreditPassOpinionVO> list = (List<AudCreditPassOpinionVO>) pager.getResultList();
		ListPageVO<AudCreditPassOpinionVO> listPage = new ListPageVO<AudCreditPassOpinionVO>(list, pager.getTotalCount());
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		try {
			this.audCreditPassOpinionService.removeById(Long.valueOf(id));
			BaseLogUtils.info(logger, "removeById", "删除数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "removeById", "删除数据失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "removeById", "删除数据失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.error(logger, "getById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			AudCreditPassOpinionVO vo = this.audCreditPassOpinionService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getById", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		AudCreditPassOpinionVO entity = null;
		try {
			entity = this.getRequestParamForAdd(request);
			Long id = this.audCreditPassOpinionService.add(entity);
			result.setData(id);
			BaseLogUtils.info(logger, "add", "新增数据.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		AudCreditPassOpinionVO entity = null;
		try {
			entity = this.getRequestParamForModify(request);
			entity.setId(Long.valueOf(id));
			boolean success = this.audCreditPassOpinionService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * TODO 信审通过意见预览
	 */
	@RequestMapping(value = "/getPreviewString.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getPreviewString(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String opnId = request.getParameter("opnId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(opnId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.error(logger, "getPreviewString", "获取数据,主键不存在.[opnId="+opnId+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			AudCreditPassOpinionVO vo = this.audCreditPassOpinionService.selectById(Long.valueOf(opnId));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getPreviewString", "获取数据,数据不存在.[id="+opnId+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getPreviewString", "获取数据.[id="+opnId+"]", CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getPreviewString", "获取失败.[id="+opnId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getPreviewString", "获取失败.[id="+opnId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	//********************私有方法********************//
	/**
	 * 获取参数信息
	 * @param request
	 * @return
	 * @throws BaseException
	 */
	private AudCreditPassOpinionVO getRequestParam(HttpServletRequest request)throws BaseException{
		String projectId = request.getParameter("projectId");//项目ID
		String proIntId = request.getParameter("proIntId");//流程实例ID
		if(StringUtils.isEmpty(proIntId)||StringUtils.isEmpty(projectId)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "项目ID和流程实例ID不能为空.");
		}
		
		String returnPct = request.getParameter("returnPct");//收益率
		String policyStandatrdsCd = request.getParameter("policyStandatrdsCd");//执行政策标准
		String standardCd = request.getParameter("standardCd");//是否符合标准
		String executeTemplateCd = request.getParameter("executeTemplateCd");//执行模板
		String operationAnalysis = request.getParameter("operationAnalysis");//运营分析
		String buyCd = request.getParameter("buyCd");//购车行为
		String lesseeAssetsCd = request.getParameter("lesseeAssetsCd");//承租人资产实力
		String carConfigCd = request.getParameter("carConfigCd");//车辆配置
		String financePlanCd = request.getParameter("financePlanCd");//融资方案
		String operationSituationCd = request.getParameter("operationSituationCd");//运营情况
		String operationExperienceCd = request.getParameter("operationExperienceCd");//运营经验
		String paymentSourceCd = request.getParameter("paymentSourceCd");//第二还款来源
		String managementSituation = request.getParameter("managementSituation");//经营状况
		String fulfilCd = request.getParameter("fulfilCd");//履行职责
		String guarantorAssetsCd2 = request.getParameter("guarantorAssetsCd2");//担保人资产实力
		String job = request.getParameter("job");//从事工作
		String business = request.getParameter("business");//主营业务
		String attitudeCd = request.getParameter("attitudeCd");//电话态度
		String riskAnalysis = request.getParameter("riskAnalysis");//风险分析
		String maneuverabilityCd = request.getParameter("maneuverabilityCd");//可操作性评价
		String opinion = request.getParameter("opinion");//审批意见
		String quantities = request.getParameter("quantities");//购买数量
		String brandModel = request.getParameter("brandModel");//品牌及规格型号
		String marketPrice = request.getParameter("marketPrice");//市场指导价
		String chinaLowestPrice = request.getParameter("chinaLowestPrice");//全国最低价
		String provinceLowestPrice = request.getParameter("provinceLowestPrice");//省内最低价
		String localLowestPrice = request.getParameter("localLowestPrice");//本地最低价
		String systemPrice = request.getParameter("systemPrice");//系统报价
		String isCarStandard = request.getParameter("isCarStandard");//车辆信息是否符合我司标准
		String registrationDt = request.getParameter("registrationDt");//初始登记日期
		String mileage = request.getParameter("mileage");//里程数
		String assetsProveCd = request.getParameter("assetsProveCd");//资产证明
		String display = request.getParameter("display");//调查报告显示
		String certificates = request.getParameter("certificates");//其他工作证明
		String incomeExpenditure = request.getParameter("incomeExpenditure");//收入支出情况
		String isInquiry = request.getParameter("isInquiry");//是否查询征信
		String overdueInfo = request.getParameter("overdueInfo");//逾期情况
		String liabilitiesInfo = request.getParameter("liabilitiesInfo");//负债情况
		String guarantInfo = request.getParameter("guarantInfo");//对外担保情况
		String isCreditStandard = request.getParameter("isCreditStandard");//征信是否符合我司标准
		String otherInfo = request.getParameter("otherInfo");//备注
		if(StringUtils.isNotEmpty(quantities) && !StringUtils.isNumeric(quantities)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "购买数量必须为正整数");
		}
		if(StringUtils.isNotEmpty(marketPrice)){
			if(!StringUtils.isUnsignedNumeric(marketPrice)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "市场指导价必须为正数.");
			}
			if(marketPrice.contains(".") && marketPrice.split("\\.")[1].length()>2){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "市场指导价必须为正数,且不能超过两位小数.");
			}
		}
		if(StringUtils.isNotEmpty(chinaLowestPrice)){
			if(!StringUtils.isUnsignedNumeric(chinaLowestPrice)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "全国最低价必须为正数.");
			}
			if(chinaLowestPrice.contains(".") && chinaLowestPrice.split("\\.")[1].length()>2){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "全国最低价必须为正数,且不能超过两位小数.");
			}
		}
		if(StringUtils.isNotEmpty(provinceLowestPrice)){
			if(!StringUtils.isUnsignedNumeric(provinceLowestPrice)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "省内最低价必须为正数.");
			}
			if(provinceLowestPrice.contains(".") && provinceLowestPrice.split("\\.")[1].length()>2){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "省内最低价必须为正数,且不能超过两位小数.");
			}
		}
		if(StringUtils.isNotEmpty(localLowestPrice)){
			if(!StringUtils.isUnsignedNumeric(localLowestPrice)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "本地最低价必须为正数.");
			}
			if(localLowestPrice.contains(".") && localLowestPrice.split("\\.")[1].length()>2){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "本地最低价必须为正数,且不能超过两位小数.");
			}
		}
		if(StringUtils.isNotEmpty(systemPrice)){
			if(!StringUtils.isUnsignedNumeric(systemPrice)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "系统报价必须为正数.");
			}
			if(systemPrice.contains(".") && systemPrice.split("\\.")[1].length()>2){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "系统报价必须为正数,且不能超过两位小数.");
			}
		}
		
		AudCreditPassOpinionVO audCreditPassOpinionVO = new AudCreditPassOpinionVO();
		if(StringUtils.isNotEmpty(projectId)){
			audCreditPassOpinionVO.setProjectId(Long.valueOf(projectId));
		}
		audCreditPassOpinionVO.setProIntId(proIntId);
		if(StringUtils.isNotEmpty(returnPct)){
			audCreditPassOpinionVO.setReturnPct(Double.valueOf(returnPct));
		}
		audCreditPassOpinionVO.setPolicyStandatrdsCd(policyStandatrdsCd);
		audCreditPassOpinionVO.setStandardCd(standardCd);
		audCreditPassOpinionVO.setExecuteTemplateCd(executeTemplateCd);
		audCreditPassOpinionVO.setOperationAnalysis(operationAnalysis);
		audCreditPassOpinionVO.setBuyCd(buyCd);
		audCreditPassOpinionVO.setLesseeAssetsCd(lesseeAssetsCd);
		audCreditPassOpinionVO.setCarConfigCd(carConfigCd);
		audCreditPassOpinionVO.setFinancePlanCd(financePlanCd);
		audCreditPassOpinionVO.setOperationSituationCd(operationSituationCd);
		audCreditPassOpinionVO.setOperationExperienceCd(operationExperienceCd);
		audCreditPassOpinionVO.setPaymentSourceCd(paymentSourceCd);
		audCreditPassOpinionVO.setManagementSituation(managementSituation);
		audCreditPassOpinionVO.setFulfilCd(fulfilCd);
		audCreditPassOpinionVO.setGuarantorAssetsCd2(guarantorAssetsCd2);
		audCreditPassOpinionVO.setJob(job);
		audCreditPassOpinionVO.setBusiness(business);
		audCreditPassOpinionVO.setAttitudeCd(attitudeCd);
		audCreditPassOpinionVO.setRiskAnalysis(riskAnalysis);
		audCreditPassOpinionVO.setManeuverabilityCd(maneuverabilityCd);
		audCreditPassOpinionVO.setOpinion(opinion);
		if(StringUtils.isNotEmpty(quantities)){
			audCreditPassOpinionVO.setQuantities(Long.valueOf(quantities));
		}
		audCreditPassOpinionVO.setBrandModel(brandModel);
		if(StringUtils.isNotEmpty(marketPrice)){
			audCreditPassOpinionVO.setMarketPrice(DecimalUtils.mul(Double.valueOf(marketPrice), 100));
		}
		if(StringUtils.isNotEmpty(chinaLowestPrice)){
			audCreditPassOpinionVO.setChinaLowestPrice(DecimalUtils.mul(Double.valueOf(chinaLowestPrice), 100));
		}
		if(StringUtils.isNotEmpty(provinceLowestPrice)){
			audCreditPassOpinionVO.setProvinceLowestPrice(DecimalUtils.mul(Double.valueOf(provinceLowestPrice), 100));
		}
		if(StringUtils.isNotEmpty(localLowestPrice)){
			audCreditPassOpinionVO.setLocalLowestPrice(DecimalUtils.mul(Double.valueOf(localLowestPrice), 100));
		}
		if(StringUtils.isNotEmpty(systemPrice)){
			audCreditPassOpinionVO.setSystemPrice(DecimalUtils.mul(Double.valueOf(systemPrice), 100));
		}
		audCreditPassOpinionVO.setIsCarStandard(isCarStandard);
		if(StringUtils.isNotEmpty(registrationDt)){
			audCreditPassOpinionVO.setRegistrationDt(DateUtils.formatStringToDate(registrationDt, DateUtils.YYYY_MM_DD));
		}
		audCreditPassOpinionVO.setMileage(mileage);
		audCreditPassOpinionVO.setAssetsProveCd(assetsProveCd);
		audCreditPassOpinionVO.setDisplay(display);
		audCreditPassOpinionVO.setCertificates(certificates);
		audCreditPassOpinionVO.setIncomeExpenditure(incomeExpenditure);
		if(StringUtils.isNotEmpty(isInquiry)){
			audCreditPassOpinionVO.setIsInquiry(Integer.valueOf(isInquiry));
		}
		audCreditPassOpinionVO.setOverdueInfo(overdueInfo);
		audCreditPassOpinionVO.setLiabilitiesInfo(liabilitiesInfo);
		audCreditPassOpinionVO.setGuarantInfo(guarantInfo);
		audCreditPassOpinionVO.setIsCreditStandard(isCreditStandard);
		audCreditPassOpinionVO.setOtherInfo(otherInfo);
		
		/**信审通过意见扩展资料*/
		List<AudCreditExtInfoVO> audCreditExtInfoVOList = new ArrayList<AudCreditExtInfoVO>();
		
		//承租人信息
		String id_tenant = request.getParameter("extId_tenant");//承租人信息ID
		String creditInfo_tenant = request.getParameter("creditInfo_tenant");//承租人信审资料
		String qualificationsInfo_tenant = request.getParameter("qualificationsInfo_tenant");//承租人资质情况
		String assetsProveCd_tenant = request.getParameter("assetsProveCd_tenant");//承租人资产证明
		String times_tenant = request.getParameter("times_tenant");//承租人融资次数
		String badRecordInfo_tenant = request.getParameter("badRecordInfo_tenant");//承租人不良记录情况
		String courtsEnforceInfo_tenant = request.getParameter("courtsEnforceInfo_tenant");//承租人法院执行情况
		String researchReport_tenant = request.getParameter("researchReport_tenant");//承租人调查报告显示
		String job_tenant = request.getParameter("job_tenant");//承租人从事工作
		String registerTm_tenant = request.getParameter("registerTm_tenant");//承租人注册时间
		String business_tenant = request.getParameter("business_tenant");//承租人主营业务
		
		if(StringUtils.isNotEmpty(times_tenant) && !StringUtils.isNumeric(times_tenant)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "购买数量必须是正整数.");
		}
		
		AudCreditExtInfoVO audCreditExtInfoVO_T = new AudCreditExtInfoVO();
		if(StringUtils.isNotEmpty(id_tenant)){
			audCreditExtInfoVO_T.setId(Long.valueOf(id_tenant));
		}
		audCreditExtInfoVO_T.setCreditInfo(creditInfo_tenant);
		audCreditExtInfoVO_T.setQualificationsInfo(qualificationsInfo_tenant);
		audCreditExtInfoVO_T.setAssetsProveCd(assetsProveCd_tenant);
		if(StringUtils.isNotEmpty(times_tenant)){
			audCreditExtInfoVO_T.setTimes(Long.valueOf(times_tenant));
		}
		audCreditExtInfoVO_T.setBadRecordInfo(badRecordInfo_tenant);
		audCreditExtInfoVO_T.setCourtsEnforceInfo(courtsEnforceInfo_tenant);
		audCreditExtInfoVO_T.setResearchReport(researchReport_tenant);
		if(StringUtils.isNotEmpty(registerTm_tenant)){
			audCreditExtInfoVO_T.setRegisterTm(DateUtils.formatStringToDate(registerTm_tenant, DateUtils.YYYY_MM_DD));
		}
		audCreditExtInfoVO_T.setBusiness(business_tenant);
		audCreditExtInfoVO_T.setJob(job_tenant);
		audCreditExtInfoVO_T.setTypeCd(AudStandingBookConstant.AUD_PASS_EXT_TYP_TENANT);//资料类型-承租人
		audCreditExtInfoVOList.add(audCreditExtInfoVO_T);
		
		//担保人信息
		String id_guarantor = request.getParameter("extId_guarantor");//担保人信息ID
		String creditInfo_guarantor = request.getParameter("creditInfo_guarantor");//担保人信审资料
		String qualificationsInfo_guarantor = request.getParameter("qualificationsInfo_guarantor");//担保人资质情况
		String assetsProveCd_guarantor = request.getParameter("assetsProveCd_guarantor");//担保人资产证明
		String relationshipCd_guarantor = request.getParameter("relationshipCd_guarantor");//担保人与承租人关系
		String researchReport_guarantor = request.getParameter("researchReport_guarantor");//担保人调查报告显示
		String job_guarantor = request.getParameter("job_guarantor");//担保人从事工作
		String registerTm_guarantor = request.getParameter("registerTm_guarantor");//担保人注册时间
		String business_guarantor = request.getParameter("business_guarantor");//担保人主营业务
		
		AudCreditExtInfoVO audCreditExtInfoVO_G = new AudCreditExtInfoVO();
		if(StringUtils.isNotEmpty(id_guarantor)){
			audCreditExtInfoVO_G.setId(Long.valueOf(id_guarantor));
		}
		audCreditExtInfoVO_G.setCreditInfo(creditInfo_guarantor);
		audCreditExtInfoVO_G.setQualificationsInfo(qualificationsInfo_guarantor);
		audCreditExtInfoVO_G.setAssetsProveCd(assetsProveCd_guarantor);
		audCreditExtInfoVO_G.setRelationshipCd(relationshipCd_guarantor);
		audCreditExtInfoVO_G.setResearchReport(researchReport_guarantor);
		if(StringUtils.isNotEmpty(registerTm_guarantor)){
			audCreditExtInfoVO_G.setRegisterTm(DateUtils.formatStringToDate(registerTm_guarantor, DateUtils.YYYY_MM_DD));
		}
		audCreditExtInfoVO_G.setBusiness(business_guarantor);
		audCreditExtInfoVO_G.setJob(job_guarantor);
		audCreditExtInfoVO_G.setTypeCd(AudStandingBookConstant.AUD_PASS_EXT_TYP_GUARANTOR);//资料类型-担保人
		audCreditExtInfoVOList.add(audCreditExtInfoVO_G);
		
		audCreditPassOpinionVO.setAudCreditExtInfoVOList(audCreditExtInfoVOList);
		
		return audCreditPassOpinionVO;
	}
	
	/**
	 * 获取请求参数(新增)
	 * @param request 请求
	 * @return 
	 */
	private AudCreditPassOpinionVO getRequestParamForAdd(HttpServletRequest request)throws BaseException{
		AudCreditPassOpinionVO audCreditPassOpinionVO = this.getRequestParam(request);
		audCreditPassOpinionVO.setCrtTm(new Date());
		audCreditPassOpinionVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		List<AudCreditExtInfoVO> audCreditExtInfoVOList = audCreditPassOpinionVO.getAudCreditExtInfoVOList();
		if(CollectionUtils.isNotEmpty(audCreditExtInfoVOList)){
			for (AudCreditExtInfoVO audCreditExtInfoVO : audCreditExtInfoVOList) {
				audCreditExtInfoVO.setCrtTm(new Date());
				audCreditExtInfoVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			}
		}
		return audCreditPassOpinionVO;
	}
	
	/**
	 * 获取请求参数(修改)
	 * @param request 请求
	 * @return 
	 */
	private AudCreditPassOpinionVO getRequestParamForModify(HttpServletRequest request)throws BaseException{
		AudCreditPassOpinionVO audCreditPassOpinionVO = this.getRequestParam(request);
		audCreditPassOpinionVO.setMdfTm(new Date());
		audCreditPassOpinionVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		List<AudCreditExtInfoVO> audCreditExtInfoVOList = audCreditPassOpinionVO.getAudCreditExtInfoVOList();
		if(CollectionUtils.isNotEmpty(audCreditExtInfoVOList)){
			for (AudCreditExtInfoVO audCreditExtInfoVO : audCreditExtInfoVOList) {
				audCreditExtInfoVO.setMdfTm(new Date());
				audCreditExtInfoVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			}
		}
		return audCreditPassOpinionVO;
	}
}

